Find Folder

© 2006, Stefan Pendl

Home

Tip Corner: ByRef

API Corner: File Download

Working with Strings 3

Stylebits Corner: Dialogs

Eddie's Lessons, v.10

Liberty Basic Wiki

Preprocessor 1

Preprocessor 2

Find Folder

Multiple Listboxes

Newsletter help

Index


Introduction

Stefan posted an excellent demo for locating folders on the Liberty Basic Forum [http://libertybasic.conforums.com]. Graciously he has consented to allowing me to republish it. In fact, this is an updated version that fixes a couple issues.


folder$(1) = "C:\"
folder$(2) = "C:\WINDOWS\system*"
folder$(3) = "C:\WINDOWS\system?2"
folder$(4) = "C:\Program*"
folder$(5) = "C:\Program*\test"
folder$(6) = "C:\boot.ini"

for count = 1 to 6
if FolderExistsEx(folder$(count), FolderName$, ShortName$) then
print "Folder: "; chr$(34); folder$(count); chr$(34); " does exist."
print "Found: "; chr$(34); FolderName$; chr$(34)
print "Short: "; chr$(34); ShortName$; chr$(34)
else
print "Folder "; chr$(34); folder$(count); chr$(34); " does not exist."
end if

print
next
end

function FolderExistsEx(Path$, byref FoundFolderName$, byref ShortFolderName$)
' checks for the existance of the given folder
'
' returns true(1) or false(0)
'
' FoundFolderName$ will hold the first found name when wildcards (? and *) are used
' ShortFolderName$ will hold the name in the 8.3 format

if right$(Path$,1) = "\" then Path$ = left$(Path$, len(Path$)-1)
if right$(Path$,1) = ":" then
if instr(Drives$, lower$(Path$)) > 0 then
FolderExistsEx = 1
FoundFolderName$ = Path$
ShortFolderName$ = Path$
exit function
end if
end if

Path$ = Path$ + chr$(0)

struct Win32FindData, _
FileAttributes as ulong, _
CreationTime.LowDateTime as ulong, _
CreationTime.HighDateTime as ulong, _
LastAccessTime.LowDateTime as ulong, _
LastAccessTime.HighDateTime as ulong, _
LastWriteTime.LowDateTime as ulong, _
LastWriteTime.HighDateTime as ulong, _
FileSizeHigh as ulong, _
FileSizeLow as ulong, _
Reserved0 as ulong, _
Reserved1 as ulong, _
FileName$ as char[260], _
AlternateFileName$ as char[14]

calldll #kernel32, "FindFirstFileA", _
Path$ as ptr, _
Win32FindData as struct,_
handle as ulong

if handle <> _INVALID_HANDLE_VALUE then
if _FILE_ATTRIBUTE_DIRECTORY and Win32FindData.FileAttributes.struct then
FolderExistsEx = 1
FoundFolderName$ = Win32FindData.FileName$.struct
ShortFolderName$ = Win32FindData.AlternateFileName$.struct
end if

calldll #kernel32, "FindClose", _
handle as ulong, _
result as boolean
end if
end function



Home

Tip Corner: ByRef

API Corner: File Download

Working with Strings 3

Stylebits Corner: Dialogs

Eddie's Lessons, v.10

Liberty Basic Wiki

Preprocessor 1

Preprocessor 2

Find Folder

Multiple Listboxes

Newsletter help

Index